﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BMC.ARSystem;
using Wicresoft.EKA.NRemedy;
using System.Collections;
using System.Threading;
using System.IO;

namespace Wicresoft.EKA.NRemedy.ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string ARServer = ConfigurationManager.AppSettings["ARServer"];
            string ARUid = ConfigurationManager.AppSettings["ARUid"];
            string ARPwd = ConfigurationManager.AppSettings["ARPwd"];

            GlobalSettings.SetCharacterEncoding("UTF8");    //GlobalSetting 里面 
            ARLoginContext context = new ARLoginContext(ARServer, ARUid, ARPwd);
            ARLoginContextPool.Instance.Add(ARUid, context);
            ARProxy<EKA_GroupModel> ar = new ARProxy<EKA_GroupModel>(context);

            int start=50000;
            using (StreamReader sr = File.OpenText("权限组.txt"))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {

                    ar.CreateEntry(new EKA_GroupModel()
                        {
                            GroupID = start,
                            GroupName = s.Trim(),
                            IsArchitectureGroup = 0,
                            IsEVM = 1,
                            ShortDescription="System"
                        });

                        start++;
                    Console.WriteLine(s.Trim());
                }
            }

            int startA=51000;

            using (StreamReader sr = File.OpenText("架构组.txt"))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    ar.CreateEntry(new EKA_GroupModel()
                    {
                        GroupID = startA,
                        GroupName = s.Trim(),
                        IsArchitectureGroup = 1,
                        IsEVM = 1,
                        ShortDescription = "System"
                    });

                    startA++;
                    Console.WriteLine(s.Trim());
                }
            }

            Console.ReadLine();


            // DateTime startTime = DateTime.Now;
            // TestModel test = new TestModel();

            // //context.BeginBulkEntryTransaction();
            // for (int i = 0; i < 2; i++)
            // {
            //     test = new TestModel()
            //     {
            //         Submitter = "Demo",
            //         ShortDescription = i.ToString(),
            //         CharacterField = "Char",
            //         CheckBoxField = 0,
            //         DateField = new BMC.ARSystem.DateValue(DateTime.Now),
            //         //DateField2 = new BMC.ARSystem.DateValue(DateTime.Now),
            //         DecimalNumberField = 1,
            //         DiaryFieldSet = "Diary",
            //         //DropDownListField = TestModel.DropDownListField_Enum.NoValue,
            //         IntegerField = 1,
            //         RadioButtonField = TestModel.RadioButtonField_Enum.Default1,
            //         RealNumberField = 1.0,
            //         TimeField = new BMC.ARSystem.TimeOfDayValue(1, 2, 3)
            //     };
            //     ar.CreateEntry(test);
            // }
            // //context.SendBulkEntryTransaction();

            // int count;
            //var entrys=   ar.GetPagedEntry(TestModel.Submitter_Name.S() + "=" + "Demo".D(),
            //     new List<uint> { TestModel.RequestID_ID, TestModel.ShortDescription_ID,TestModel.DropDownListField_ID },
            //     0, 10, out count,
            //     new ArrayList() { new SortInfo((int)TestModel.RequestID_ID, SortInfo.SortOrder.Descending) });

            //Console.WriteLine(startTime.ToString());
            //Console.WriteLine(DateTime.Now.ToString());
        }
    }
}
